/*
 * DevCalc.h
 *
 *  Created on: 14.11.2012
 *      Author: fs
 */

#ifndef DEVCALC_H_
#define DEVCALC_H_

#include "GenCalc.h"
#include "CsvLoader.h"
#include "Configuration.h"

#include <vector>
#include <boost/random.hpp>

#define DECREASE_RATE 1.5
#define CROSS_RATE 0.5
#define MUTATION_RATE 0.05

#define WORSE_FITTNES 1000000

#define MINUTE 60 * 24

struct member
{
	double* gens;
	double fitness;
	double selectionFitness;
};


class GenCalc
{
public:
	virtual ~GenCalc();

	GenCalc(data* datas, Configuration* conf);
	void initPopulation();
	void nextGeneration();
	void nextEvolution(int generation);

	double getBestFitness();
	double bestFittnes;
	std::vector<member> population;

	int getIg(double time, double *ig);
	bool checkTimeCondition(double k, double dt, double ecg);

	void writeFittnesAtPosition(double fitness, int index);

	double* getBestMember();

	void compute();

private:

	data* datas;
	Configuration* conf;

	double mutationRate;
	int threadCount;
	double* bestMember;


	int find_time(unsigned int time);

	int pickMember();
	double fitness(member inputMember);
	int sumSelection;

	void crossover(double* result, double* first, double* second);
	void mutate(double* gens);
	void printBest(int generation);

	void rankPopulation();

	void applyConfigurationState(double* &gens);

};

#endif /* DEVCALC_H_ */
